package com.util;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.siyue.bean.vo.AccessDeviceExcelVo;
import com.siyue.bean.vo.AccessDeviceExcelListener;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

public class ExcelUtil {

    String filePath="D:\\jianxin\\项目\\开发文档\\门禁设备导入.xlsx";
    @Test
    public void test1() throws FileNotFoundException {
        File file=new File(filePath);
        FileInputStream fis = new FileInputStream(file);
        List<AccessDeviceExcelVo> accessDeviceExcelVos= EasyExcel.read(fis)
                //注册自定义监听器，字段校验可以在监听器内实现
                .registerReadListener(new AccessDeviceExcelListener())
                .head(AccessDeviceExcelVo.class)
                .sheet(0)
                .headRowNumber(1)
                .doReadSync();

        //
//        System.out.println(accessDeviceExcelVos.toArray());
    }


    /**
     * 检验ip是否正确
     * @throws FileNotFoundException
     */
    @Test
    public void checkIp() throws FileNotFoundException {
        String ip="192.168.137.2";
        boolean bool=ip.matches("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}");
        System.out.println(bool);
    }


    /**
     * 检验端口是否正确
     * @throws FileNotFoundException
     */
    @Test
    public void checkPort() throws FileNotFoundException {
        String port="8080";
        boolean bool=port.matches( "^(\\d{1,5}|[1-5]\\d{5}|6[0-4]\\d{4}|65[0-4]\\d{3}|655[0-2]\\d{2}|6553[0-5])$");
        System.out.println(bool);
    }
}


